﻿namespace Infrastructure.Utils
{
    public class FileHelper
    {
        #region web下载文件到本地
        /// <summary>
        /// web下载文件到本地
        /// </summary>
        /// <param name="src">资源地址</param>
        /// <param name="savePath">保存路径[若没有则创建]</param>
        /// <returns></returns>
        public static async Task DownFile(string src, string savePath)
        {
            //eg: FileHelper.DownFile("https://www.baidu.com/img/baidu_jgylogo3.gif", "h:/4tmp/downLoad/baidu.png");
            var response = await new HttpClient().GetAsync(src);
            using var fileStream = new FileStream(savePath, FileMode.OpenOrCreate, FileAccess.Write);
            await response.Content.CopyToAsync(fileStream);
        }
        #endregion

    }
}
